package com.mephi.oshs.model.interpreter.impl;

import com.mephi.oshs.model.interpreter.api.IContext;
import com.mephi.oshs.model.interpreter.api.IExpression;

public class ContainsExpression extends ComparisonExpression {

    public ContainsExpression(final IExpression expressionA, final IExpression expressionB) {
        super(expressionA, expressionB);
    }

    public void interpret(final IContext c) {
        expressionA.interpret(c);
        expressionB.interpret(c);
        final Object exprAResult = c.get(expressionA);
        final Object exprBResult = c.get(expressionB);
        if ((exprAResult instanceof String) && (exprBResult instanceof String)) {
            if (((String) exprAResult).contains((String) exprBResult)) {
                c.addVariable(this, Boolean.TRUE);
                return;
            }
        }
        c.addVariable(this, Boolean.FALSE);
    }
}
